import { getAreaObj, regularRule, uploadType } from '@/utils/util'
import { getStore } from '@/utils/store'

const userInfo = getStore('userInfo') || {}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '摄像头编号',
			prop: 'videoNum',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入摄像头编号' }],
		},
		{
			label: '摄像头类型',
			prop: 'videoType',
			propName: 'videoTypeLabel',
			type: 'remoteSelect',
			code: 'VIDEO_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			rules: [{ required: true, message: '请选择摄像头类型' }],
			span: 12,
		},

		{
			label: '摄像头位置',
			prop: 'videoLocation',
			propName: 'videoLocationLabel',
			span: 12,
			type: 'remoteSelect',
			code: 'VIDEO_LOCATION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			rules: [{ required: true, message: '请输入摄像头位置' }],
		},
		{
			label: '楼层房间号',
			prop: 'videoFloor',
			// propName: 'videoFloorText',
			type: 'BuildRoomBed',
			deepLevel: 2,
			display: !(userInfo.classifyId == 4 && userInfo.userType == 3),
			span: 12,
		},
		{
			label: '摄像头账号',
			prop: 'videoUsername',
			type: 'input',
			span: 12,
		},
		{
			label: '摄像头账号密码',
			prop: 'videoPasswd',
			type: 'input',
			span: 12,
		},
		{
			label: 'ip地址',
			prop: 'videoIp',
			type: 'input',
			span: 12,
		},
		{
			label: '播放地址',
			prop: 'videoUri',
			type: 'input',
			span: 24,
			rules: [
				{ required: true, message: '请输入播放地址' },
				{ pattern: regularRule.httpOrhttps, message: '请输入正确的播放地址必须是http或https 开头' },
			],
		},
		{
			label: '默认封面',
			tip: '',
			prop: 'posterImg',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
	],
}

export const spotCheckForm = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '抽查问题内容',
			prop: 'videoContent',
			type: 'textarea',
			maxlength: '500',
			rows: 1,
			showWordLimit: true,
			span: 24,
		},
		{
			label: '抽查问题图片',
			prop: 'videoPic',
			type: 'DragUpload',
			itemWidth: '30%',
			dataType: 'string',
			// fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
	],
}
export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '所属单位',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '摄像头编号',
			prop: 'videoNum',
			type: 'input',
			span: 8,
		},
		{
			label: '摄像头类型',
			prop: 'videoType',
			propName: 'videoTypeLabel',
			type: 'remoteSelect',
			code: 'VIDEO_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '摄像头位置',
			prop: 'videoLocation',
			span: 8,
			type: 'remoteSelect',
			code: 'VIDEO_LOCATION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	tableLayout: 'auto',
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{ label: '摄像头编号', prop: 'videoNum' },
		{ label: '摄像头类型', prop: 'videoTypeLabel' },
		{ label: '摄像头位置', prop: 'videoLocation', code: 'VIDEO_LOCATION', custome: 'tag' },
		{ label: '账号', prop: 'videoUsername' },
		{ label: '密码', prop: 'videoPasswd' },
		{ label: '播放地址', prop: 'videoPlay' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
export const tableConfigNoMenu = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{ label: '摄像头编号', prop: 'videoNum' },
		{ label: '摄像头类型', prop: 'videoTypeLabel' },
		{ label: '摄像头位置', prop: 'videoLocation', code: 'VIDEO_LOCATION', custome: 'tag' },
		{ label: '账号', prop: 'videoUsername' },
		{ label: '密码', prop: 'videoPasswd' },
		{ label: '播放地址', prop: 'videoPlay' },
	],
}

export const api = {
	index: 'view_pbVideoSurveillance_page',
	add: 'view_pbVideoSurveillance_add',
	edit: 'view_pbVideoSurveillance_edit',
	delete: 'view_pbVideoSurveillance_del',
	export: 'view_pbVideoSurveillance_export',
	spot: 'view_scSpotCheckMonitor_add',
	// authArea: 'authArea',
}
export const baseConfig = {
	pageName: '视频监控',
	dictcodes: ['VIDEO_TYPE', 'VIDEO_LOCATION'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'videoNum',
	exportMqTopic: '/ning/export/',
	loadOrgInfo: true,
	api,
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	paramsObj: {},
	menuBtn: [
		{
			label: '抽查处理',
			type: 'primary',
			operate: 'spotCheck',
			auth: 'view_scSpotCheckMonitor_add',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			form = {
				...form,
				videoFloor: form.videoFloor?.join('/'),
			}
			resolve(form)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					item.videoUri = item.videoUri.replaceAll('&amp;', '&')
					return item
				})
			)
		})
	},
	operateFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
